package com.cebbank.sz.cebtemplate.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cebbank.sz.cebtemplate.dao.UserMapper;
import com.cebbank.sz.cebtemplate.model.po.User;
import com.cebbank.sz.cebtemplate.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * Created by Jaco on 2019/11/28.
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public String  showUsers()
	{
		List<User> userList = userMapper.selectList(null);
		String result="";
		for(User s:userList){
			result+= s.toString()+"\n";
		}
		return result;
	}

	@Override
	public List<User> selectUserList(int pageNo, int pageSize) {
		Integer endPage=pageNo*pageSize;
		Integer startPage=((pageNo-1)*pageSize+1);
		Map<String,Integer> map=new HashMap<>();
		map.put("startPage",startPage);
		map.put("endPage",endPage);
		List<User> userList=userMapper.selectUserList(map);
		return userList;
	}


    @Override
	public IPage<User> selectPage(int pageNo,int pageSize){
		LambdaQueryWrapper<User> userLambdaQueryWrapper = Wrappers.lambdaQuery();
		userLambdaQueryWrapper.ge(User::getId , "1000");
		Page<User> userPage = new Page<>(pageNo , pageSize);
		userPage.setTotal(1000000);
		IPage<User> userIPage = userMapper.selectPage(userPage , userLambdaQueryWrapper);
		System.out.println("总页数： "+userIPage.getSize());
		System.out.println("总记录数： "+userIPage.getCurrent());
//		userIPage.getRecords().forEach(System.out::println);
		return userIPage;
	}



}
